<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>'成员列表']"/>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<script type="text/html" id="toolbarAE">
            <div class="layui-btn-container">
			<?php echo SysRolCk("member_add")?'<button class="layui-btn layui-btn-sm data-add-btn"><i class="layui-icon">&#xe61f;</i>'.lang('add').'</button>':''; ?> 
            </div>
        </script>

			<table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

			<script type="text/html" id="imgTpl"><img src="{{d.photo}}"  width="40" height="30"></script>

			<script type="text/html" id="switchTpl">
			<input type="checkbox" name="status" id="{{d.id}}" value="{{d.status}}" lay-skin="switch" lay-text="显示|不显示"
				lay-filter="switchStatus" {{ d.status == 1 ? 'checked' : '' }}>
			</script>

			<script type="text/html" id="currentTableBar">
				<div class="layui-btn-group">
		<?php echo SysRolCk("member_edit")?' <a class="layui-btn layui-btn-sm data-count-edit" lay-event="edit"><i class="layui-icon">&#xe642;</i>'.lang('edit').'</a>':''; ?> 
		<?php echo SysRolCk("member_del")?'<a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>'.lang('del').'</a>':''; ?> 
       </div> </script>

		</div>
	</div>

</div>

<script>
	layui.define(function () {
		var table = layui.table,
			$ = layui.jquery,
			form = layui.form;
		table.render({
			elem: '#currentTableId',
			url: '<{CAUrl("member","index")}>&list_json',
			toolbar: '#toolbarAE',
			defaultToolbar: ['filter', 'exports', 'print', {
				title: '提示',
				layEvent: 'LAYTABLE_TIPS',
				icon: 'layui-icon-tips'
			}],
			page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
				layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
				//,curr: 5 //设定初始在第 5 页
				, groups: 1 //只显示 1 个连续页码
				, first: false //不显示首页
				, last: false //不显示尾页
			},
			cols: [[
				//{type: "checkbox", width: 50, fixed: "left"},
				{ field: 'id', width: 80, title: 'ID', sort: true },
				{ field: 'sort', width: 100,  title: '单位排序', align: "center" },
				{ field: 'name', width: 120, title: '姓名' , align: "center"},
				{ field: 'duties', title: '职务' },
				{ field: 'photo', width: 120,  title: '照片' ,templet: '#imgTpl', unresize: true, align: "center"},
				{ field: 'duty', title: '分管工作'},
				{ field: 'status', width: 200, title: '前台是否显示', sort: true, templet: '#switchTpl', unresize: true },
				{ title: '操作', width: 200, templet: '#currentTableBar', fixed: "right", align: "center" }
			]],
			limits: [10, 15, 20, 25, 50, 100],
			limit: 15,
			page: true
		});


		// 监听添加操作
		$(".data-add-btn").on("click", function () {
			loadMain('<{CAUrl("member","add")}>&view');
			return false;
		});
		// 监听删除操作
		$(".data-delete-btn").on("click", function () {
			var checkStatus = table.checkStatus('currentTableId')
				, data = checkStatus.data;
			layer.alert(JSON.stringify(data));
		});

		//监听表格复选框选择
		table.on('checkbox(currentTableFilter)', function (obj) {
			console.log(obj)
		});

		//监听状态操作
		form.on('switch(switchStatus)', function (obj) {
			$.post('<{CAUrl("member","edit")}>&switchStatus', 
			{ id: this.id, status: obj.elem.checked?1:0,att:obj.elem.name },
			function (res) {
				layer.tips(res.info,obj.othis,{
					tips: 2
					});
				});
		});



		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				loadMain('<{CAUrl("member","edit")}>&view&id=' + data.id);
				return false;
			} else if (obj.event === 'delete') {
				layer.confirm('真的删除么', function (index) {
					$.post('<{CAUrl("member","del")}>', data, function (res) {
						if (res.status == 1) {
							layer.msg(res.info, { icon: 1, time: 1000 }, function () {
								obj.del();
								// 关闭弹出层
								layer.close(index);
							});
						} else {
							layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
						}
					});
				});
			}
		});
	});
</script>